package tcu.iot.gasmanage.api;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import tcu.iot.gasmanage.common.Result;
import tcu.iot.gasmanage.common.utils.QuerySwitchUtils;
import tcu.iot.gasmanage.entity.alarm.AlarmEventsQuery;
import tcu.iot.gasmanage.service.AlarmService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(value = "报警信息控制器")
@RestController
@ResponseBody
@RequestMapping("/alarmEvents")
@CrossOrigin
public class AlarmController {

    @Resource
    private AlarmService alarmService;

    @ApiOperation(value = "/list", notes = "获取所有报警设备信息数据")
    @GetMapping(value = "/list")
    public Result getAlarmList(HttpServletRequest request) {
        AlarmEventsQuery alarmEventsQuery = JSON.parseObject(QuerySwitchUtils.QuerySwitch(request.getQueryString()), AlarmEventsQuery.class);

        System.out.println(alarmEventsQuery);
        return alarmService.getAlarmData(alarmEventsQuery);
    }
}
